home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nannws33.zip / TEXTSENS.PRG < prev    next >
Text File  |  1988-11-01  |  2KB  |  99 lines

  1. * Program: TextSens.prg
  2. * Author:  David R. Alison
  3. * Version: Clipper Summer '87
  4. * Note(s): Example of a text-sensitive ACHOICE().
  5. * Public Domain Software.
  6.  
  7. * Set up the frame for ACHOICE().
  8. frame = CHR(201) + CHR(205) + CHR(187) +;
  9.         CHR(186) + CHR(188) + CHR(205) +;
  10.         CHR(200) + CHR(186)
  11.  
  12. * Load the current directory into the array "names" and
  13. * sort it in ascending order.
  14. DECLARE names[ADIR('*.*' )]
  15. ADIR('*.*', names)
  16. ASORT(names)
  17.  
  18. * Initialize init (initial element) and rel (relative
  19. * window row) for ACHOICE().  Also initilize s_name,
  20. * the search variable for the array "names."
  21. PUBLIC init, rel, s_name
  22.  
  23. * Display the box.
  24. CLEAR
  25. @ 7, 34, 15, 47 BOX frame
  26. @ 16, 34, 18, 47 BOX frame
  27. init = 1
  28. rel = 1
  29. s_name = ''
  30. DO WHILE 1 = 1
  31.     @ 17, 35 SAY s_name + SPACE(12 - LEN(s_name))
  32.     choice = ACHOICE(8, 35, 14, 46, names, .t., + ;
  33.                       'SeekText', init, rel)
  34.     s = LASTKEY()
  35.     DO CASE
  36.     CASE s = 13
  37.        * The last key was Enter.
  38.        EXIT
  39.         
  40.     CASE s = 27
  41.        * The Escape key was pressed.
  42.        choice = 0
  43.        EXIT
  44.         
  45.     CASE s = 8
  46.        * The Backspace key was pressed.
  47.        s_name = SUBSTR(s_name, 1, LEN(s_name) - 1)
  48.        init = choice
  49.        LOOP
  50.  
  51.     CASE s < 33
  52.        * Either the space bar or possibly an arrow
  53.        * key was pressed.
  54.        s_name = ''
  55.        init = choice
  56.        LOOP
  57.         
  58.     OTHERWISE
  59.        * Conduct the search here using ASCAN().
  60.        s_name = s_name + UPPER(CHR(LASTKEY()))
  61.        init = choice
  62.        i = ASCAN(names, s_name)
  63.        IF i = 0
  64.           s_name = SUBSTR(s_name, 1, LEN(s_name) - 1)
  65.           TONE(900, 2)       && Error indicator.
  66.        ELSE
  67.           init = i
  68.        ENDIF
  69.  
  70.     ENDCASE
  71. ENDDO
  72. IF choice = 0
  73.    ? 'Selection Aborted...'
  74. ELSE
  75.    ? 'You selected ' + names[choice]
  76. ENDIF
  77.  
  78.  
  79. FUNCTION SeekText
  80. PARAMETERS minit, mrel
  81. init = minit
  82. rel = mrel
  83.  
  84. DO CASE
  85. CASE LASTKEY() = 13 .OR. LASTKEY() = 27
  86.    RETURN(1)
  87.     
  88. CASE LASTKEY() = 32 .OR. LASTKEY() = 8
  89.    RETURN(1)
  90.     
  91. CASE LASTKEY() < 30
  92.    s_name = ''
  93.    @ 17, 35 SAY s_name + SPACE(10 - LEN(s_name))
  94.    RETURN(2)
  95. ENDCASE
  96. RETURN(1)
  97.  
  98. * EOP: TextSens.prg
  99.